package com.wxzl.community.common.utils.ext

import android.text.method.ReplacementTransformationMethod
import android.widget.EditText

/**
 * @Author: LiaoZhongKai
 * @Date: 2021/5/6 14:50
 * @Description:
 */

/**
 * 校验是否是正确的手机号码
 */
fun EditText.isPhone(): Boolean{
    val text = this.text?.toString()
    if (!text.isNullOrEmpty()){
        val regex = Regex("[1][34578]\\d{9}")
        return text.matches(regex)
    }
    return false
}

/**
 * 校验身份证号是否正确
 */
fun EditText.checkIDNumber(): Boolean{
    val text = this.text?.toString()
    if (!text.isNullOrEmpty()){
        val regex = Regex("(^\\d{15}$)|(^\\d{17}([0-9]|X)$)")
        return text.toUpperCase().matches(regex)
    }
    return false
}

/**
 * 小写转大写
 */
class LowerToUpperCaseTransMethod : ReplacementTransformationMethod(){
    override fun getOriginal(): CharArray {
        return charArrayOf('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
    }

    override fun getReplacement(): CharArray {
        return charArrayOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
    }

}

